Skip to content

Commit

Permalink
Added the ability to loop through all videos in a category folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
eat-sleep-code committed Oct 12, 2020
1 parent 1c29bea commit 5848b3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tiny-tv <input> [options]

### Options

+ _--input_ : Select the video to be played *(required, can be a file name or a Youtube URL)*
+ _--input_ : Select the video to be played *(required, can be a file name, a Youtube URL, or the word 'category')*
+ _--saveAs_ : Enter the name you would like the file saved as *(Used if downloading from YouTube only)*
+ _--category_ : Select the category *(This will set the subfolder, for example `--category cartoons` will use the `/home/pi/videos/cartoons` folder)*
+ _--maximumVideoHeight_ : Set the maximum height (in pixels) for downloaded videos *(default: 480)*
Expand Down Expand Up @@ -90,6 +90,12 @@ Alternatively, you can type the video subfolder instead of using the category ar
```
tiny-tv 'music/Becky G - Mayores (featuring Bad Bunny).mp4' --volume 300
```

#### To play all the cartoons in a loop:

```
tiny-tv 'category' --category 'cartoons' --volume 100
```
---

## Audio Settings
Expand Down
30 changes: 18 additions & 12 deletions tiny-tv.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from datetime import datetime
from time import sleep
import argparse
import glob
import os
import subprocess
import shutil
import sys
import youtube_dl

version = '2020.09.24'
version = '2020.10.12'

# === Argument Handling ========================================================

Expand Down Expand Up @@ -47,31 +48,31 @@
# ------------------------------------------------------------------------------

removeVerticalBars = args.removeVerticalBars or False
if str(removeVerticalBars) == "True":
if str(removeVerticalBars) == 'True':
removeVerticalBars = True
else:
removeVerticalBars = False

# ------------------------------------------------------------------------------

removeHorizontalBars = args.removeHorizontalBars or False
if str(removeHorizontalBars) == "True":
if str(removeHorizontalBars) == 'True':
removeHorizontalBars = True
else:
removeHorizontalBars = False

# ------------------------------------------------------------------------------

resize = args.resize or False
if str(resize) == "True":
if str(resize) == 'True':
resize = True
else:
resize = False

# ------------------------------------------------------------------------------

loop = args.loop or True
if str(loop) == "False":
if str(loop) == 'False':
loop = False
else:
loop = True
Expand Down Expand Up @@ -124,15 +125,16 @@ def getVideoPath(inputPath):
print('\n Tiny TV ' + version )
print('\n ----------------------------------------------------------------------\n')
print('\n Press [Ctrl]-C to exit. \n')

if input.find('.') == -1 and input.find(';') == -1:

input = input.lower().strip()
if input.find('.') == -1 and input.find(';') == -1 and input != 'category':
input = input + '.mp4'
video = input


# --- YouTube Download -------------------------------------------------

if input.find('youtube.com') != -1:
if video.find('youtube.com') != -1:
print(' Starting download of video... ')
downloadHeight = 720
if maximumVideoHeight >= 4320: # Future product
Expand All @@ -148,7 +150,7 @@ def getVideoPath(inputPath):
'format': 'best[height=' + str(downloadHeight) + ']'
}
with youtube_dl.YoutubeDL(youtubeDownloadOptions) as youtubeDownload:
info = youtubeDownload.extract_info(input)
info = youtubeDownload.extract_info(video)
video = info.get('id', None) + '.' + info.get('ext', None)
except Exception as ex:
print(' Falling back to best quality video... ')
Expand All @@ -157,7 +159,7 @@ def getVideoPath(inputPath):
'format': 'best'
}
with youtube_dl.YoutubeDL(youtubeDownloadOptions) as youtubeDownload:
info = youtubeDownload.extract_info(input)
info = youtubeDownload.extract_info(video)
video = info.get('id', None) + '.' + info.get('ext', None)
pass

Expand Down Expand Up @@ -202,8 +204,12 @@ def getVideoPath(inputPath):
while playCount >= 0:
playCount += 1
print('\n Starting playback (' + str(playCount) + ') at ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ' ...')
videoFullPath = videoCategoryFolder + str(video)
subprocess.call('omxplayer -o alsa --vol ' + str(volume) + ' "' + videoFullPath + '"', shell=True)
if (video == 'category'):
for videoFullPath in glob.glob(videoCategoryFolder + '**/*.mp4', recursive = True):
subprocess.call('omxplayer -o alsa --vol ' + str(volume) + ' "' + videoFullPath + '"', shell=True)
else:
videoFullPath = videoCategoryFolder + str(video)
subprocess.call('omxplayer -o alsa --vol ' + str(volume) + ' "' + videoFullPath + '"', shell=True)
if loop == False:
break
else:
Expand Down

0 comments on commit 5848b3f

Please sign in to comment.